import os, django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'settings.config')
django.setup()
from settings import config
from celery import Celery
from datetime import timedelta
from celery.schedules import crontab

broker = config.CELERY_BROKER_URL
backend = config.CELERY_BROKER_URL
include = ['celery_task.tasks']
app = Celery(broker=broker, backend=backend, include=include)

## app的配置文件
# 时区
app.conf.timezone = 'Asia/Shanghai'

# 是否使用UTC
app.conf.enable_utc = False

app.conf.beat_schedule = {
    # 任务名可以随意写
    'user_sync': {
        ## 指定任务源
        'task': 'celery_task.tasks.ldap_sync_user',
        ## 延迟时间: 每60秒一次
        'schedule': timedelta(seconds=60),
        ## 传递参数
        'args': ({'first_name': 'givenName', 'last_name': 'sn', 'alias': 'sn', 'email': 'mail', 'username': 'cn'},),
    }
}